const app = getApp();

// pages/order/afterSale/afterSale.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hide: app.globalData.hide,
    checkType: false,
    checkResult: false,
    type: "",
    result: "",
    afterSaleType: ["换货", "退货", "仅退款"],
    afterSaleResult: [
      "不喜欢/不想要了",
      "多选/错选/重新选择",
      "商品质量问题",
      "选错地址",
      "其他",
    ],
    pageType: 0,
  },

  // 显示
  showType() {
    const that = this;
    that.setData({ checkType: true });
  },

  showResult() {
    this.setData({ checkResult: true });
  },

  //   确认
  typeConfirm(e) {
    const { value } = e.detail;
    wx.nextTick(() => {
      this.setData({
        checkType: false,
        type: value,
      });
    });
  },

  resultConfirm(e) {
    const { value } = e.detail;
    wx.nextTick(() => {
      this.setData({
        checkResult: false,
        result: value,
      });
    });
  },

  //   取消
  typeCancel() {
    wx.nextTick(() => {
      this.setData({
        checkType: false,
      });
    });
  },

  resultCancel() {
    wx.nextTick(() => {
      this.setData({
        checkResult: false,
      });
    });
  },

  goToBack() {
    const { type, result } = this.data;
    if (type == "" || result == "") {
      wx.showToast({
        title: "请输入内容",
        icon: "error",
      });
      return;
    }
    wx.navigateBack({
      delta: 1,
    });
    wx.showToast({
      title: "申请成功",
      icon: "success",
    });
  },

  cancelAfterSale() {
    wx.showModal({
      title: "操作提示",
      content: "确定要取消该订单售后吗？",
      confirmColor: "#66a6ff ",
      success: (result) => {
        if (result.confirm) {
          wx.navigateBack({
            delta: 1,
          });
          wx.showToast({
            title: "取消成功",
            icon: "success",
          });
        }
      },
      fail: () => { },
      complete: () => { },
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { pageType } = options;
    this.setData({
      pageType,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});
